<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/js/html5.js"></script>
    <script type="text/javascript" src="/js/respond.min.js"></script>
    <script type="text/javascript" src="/js/PIE_IE678.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="/css/H-ui.css"/>
    <link type="text/css" rel="stylesheet" href="/css/H-ui.admin.css"/>
    <link type="text/css" rel="stylesheet" href="/font/font-awesome.min.css"/>
    <!--[if IE 7]>
    <link href="/font/font-awesome-ie7.min.css" rel="stylesheet" type="text/css"/>

    <![endif]-->
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <!--bootstrap-->
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/js/bootstrap/css/bootstrap.min.css"/>
    <!--bootstrap-toastr-->
    <script type="text/javascript" src="/js/toastr/toastr.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/js/toastr/toastr.css"/>
    <title>角色管理</title>
</head>

<body>
<nav class="Hui-breadcrumb"><i class="icon-home"></i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span
        class="c-gray en">&gt;</span> 角色管理 <a class="btn btn-success radius r mr-20"
                                              style="line-height:1.6em;margin-top:3px"
                                              href="javascript:location.replace(location.href);" title="刷新"><i
        class="icon-refresh"></i></a></nav>
<div class="pd-20">
    <div class="cl pd-5 bg-1 bk-gray">
    <span class="l">
      <a href="javascript:;" onClick="datadel()" class="btn btn-danger radius"><i class="icon-trash"></i> 批量删除</a>
      <a class="btn btn-primary radius" href="javascript:;"
         onClick="admin_role_add('800','500','添加角色','/role/toAdd')"><i class="icon-plus"></i> 添加角色</a>
    </span>
        <span class="r">共有数据：<strong>54</strong> 条</span>
    </div>
    <table class="table table-border table-bordered table-hover table-bg">
        <thead>
        <tr>
            <th scope="col" colspan="6">角色管理</th>
        </tr>
        <tr class="text-c">
            <th width="25"><input type="checkbox" value="" name=""></th>
            <th width="40">ID</th>
            <th width="200">角色名</th>
            <th>用户列表</th>
            <th width="300">描述</th>
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody id="role_info">
<!--        <tr class="text-c">-->
<!--            <td><input type="checkbox" value="" name=""></td>-->
<!--            <td>1</td>-->
<!--            <td>超级管理员</td>-->
<!--            <td><a href="javascript:;">admin</a></td>-->
<!--            <td>拥有至高无上的权利</td>-->
<!--            <td class="f-14"><a title="编辑" href="javascript:;"-->
<!--                                onClick="admin_role_edit('1','750','','角色编辑','admin-role-add.html')"-->
<!--                                style="text-decoration:none"><i class="icon-edit"></i></a> <a title="删除"-->
<!--                                                                                              href="javascript:;"-->
<!--                                                                                              onClick="admin_role_del(this,'1')"-->
<!--                                                                                              class="ml-5"-->
<!--                                                                                              style="text-decoration:none"><i-->
<!--                    class="icon-trash"></i></a></td>-->
<!--        </tr>-->
        </tbody>
    </table>
</div>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/layer/layer.min.js"></script>
<script type="text/javascript" src="/js/H-ui.js"></script>
<script type="text/javascript" src="/js/H-ui.admin.js"></script>

</body>
<script>
    $(function () {
        getRole();
    })

    function getRole() {
        $.ajax({
            url: "/role",
            dataType: "json",
            type: "get",
            // async: false,
            success: function (result) {
                // console.log(result);
                var data = result.data;
                var content = '';
                for (var i = 0; i < data.length; i++) {
                    content += '<tr class="text-c">';
                    content += '<td><input type="checkbox" value="" name=""></td>';
                    content += '<td>' + data[i].id + '</td>';
                    content += '<td>' + data[i].name + '</td>';
                    content += '<td><a href="javascript:;">admin</a></td>';
                    content += '<td>拥有至高无上的权利</td>';
                    content += '<td class="f-14"><a title="编辑" href="javascript:;" ' +
                        'onClick="admin_role_edit(\'1\',\'750\',\'\',\'角色编辑\',\'/role/toUpdate/' + data[i].id + '\')" ' +
                        'style="text-decoration:none"><i class="icon-edit"></i></a> <a title="删除" href="javascript:;" ' +
                        'onClick="role_del(this,\'' + data[i].id + '\')" class="ml-5" style="text-decoration:none"><i class="icon-trash"></i></a></td>';
                    content += '</tr>';
                }
                $("#role_info").html(content);
            },
            error: function (e) {
                console.log(e);
            }
        })
    }

    function role_del(obj, id) {
        layer.confirm('角色删除须谨慎，确认要删除吗？', function (index) {
            // alert(id);
            $.ajax({
                url: "/role/" + id,
                dataType: "json",
                type: "delete",
                success: function (result) {
                    console.log(result);
                    if (result.code == 200){
                        toastr.success("成功");
                        setTimeout(function () {
                            location.reload();
                        }, 1000);
                    } else{
                        toastr.success("异常");
                        setTimeout(function () {
                            location.reload();
                        }, 1000);
                    }
                },
                error: function (e) {
                    console.log(e);
                    toastr.error("系统异常");
                }
            })
            layer.msg('已删除!', 1);
        });
    }

</script>
</html>